package com.fzb.blog.controlle;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import com.fzb.blog.model.LeaveMessage;
import com.fzb.blog.vo.RespJson;
import com.mysql.jdbc.StringUtils;

public class LeaveMessageControl extends BaseControl {
	public void addMessage(){
		RespJson rj=new RespJson();
		String name=getPara("name","");
		String company=getPara("company","");
		String email=getPara("email","");
		String phone=getPara("phone","");
		String message=getPara("message","");
		if(StringUtils.isNullOrEmpty(name)||StringUtils.isNullOrEmpty(email)||StringUtils.isNullOrEmpty(phone)||StringUtils.isNullOrEmpty(message)){
			rj.setCode(-1);
			rj.setMsg("参数错误");
			renderJson(rj);
			return;
		}
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		new LeaveMessage().set("name", name)
		.set("company", company)
		.set("email", email)
		.set("phone", phone)
		.set("message", message)
		.set("createtime", System.currentTimeMillis())
		.set("createdaytime", sdf.format(new Timestamp(System.currentTimeMillis())))
		.save();
		rj.setCode(0);
		rj.setMsg("留言已提交成功，我们会尽快联系您");
		renderJson(rj);
	}
}
